package com.cc;

import domain.Book;

/**
 * @author cpp
 * @version 1.0
 * @date 2025/3/18 15:54
 * @description
 */

public class OOPDemo5 {
    public static void main(String[] args) {
        Book[] books = new Book[5];//依次存入书本的信息
        books[0] = new Book(1, "《从入门到精通》", "张三", 88, 100, 1000, "static/img/1.jpg");
        books[1] = new Book(2, "《从入门到放弃》", "李四", 89, 200, 800, " static/img/1.jpg");
        books[2] = new Book(3, "《从入门到脱发》", "王五", 56, 10, 500, " static/img/1.jpg");
        books[3] = new Book(4, "《从入门到吃药》", "赵六", 100, 180, 900, " static/img/1.jpg");
        books[4] = new Book(5, "《从入门到升仙》", "钱七", 99, 0, 1000, "  static/img/1.jpg");
        System.out.println("没比较前的排序");
        for (int i = 0; i < books.length; i++) {
            System.out.println(books[i].getInfo());
        }
        System.out.println("比较后的排序");
        for (int i = 0; i < books.length; i++) {
            for (int j = 0; j < books.length - 1; j++) {
                if (books[j].getSales() < books[j + 1].getSales()) {
                    Book temp = books[j];
                    books[j] = books[j + 1];
                    books[j + 1] = temp;
                }
            }

        }
        for (int i = 0; i < books.length; i++) {
            System.out.println(books[i].getInfo());
        }

    }
}
